//
// Created by ftd on 2021/8/19.
// 随机数辅助类
//

#ifndef DEMO_RAND_HELPER_H
#define DEMO_RAND_HELPER_H

#include <random>
#include <chrono>

static std::default_random_engine engine_32{ (unsigned int)std::chrono::system_clock::now().time_since_epoch().count() };
static std::mt19937_64 engine_64{ (long unsigned int)std::chrono::system_clock::now().time_since_epoch().count() };

template<typename T>
inline T Rand(T max) {
    if (0 == max)
        return max;
    if (max > 0) {
        std::uniform_int_distribution<T> dis(static_cast<T>(0), max-1);
        return dis(engine_32);
    }
    else {
        std::uniform_int_distribution<T> dis(max, static_cast<T>(0));
        return dis(engine_32);
    }
    return static_cast<T>(0);
}

template<typename T>
inline T Rand(T min, T max) {
    std::uniform_int_distribution<T> dis(min, max);
    return dis(engine_32);
}

template<typename T>
inline T Rand_64(T max) {
    if (0 == max)
        return max;
    if (max > 0) {
        std::uniform_int_distribution<T> dis(0, max-1);
        return dis(engine_64);
    }
    else {
        std::uniform_int_distribution<T> dis(max, 0);
        return dis(engine_64);
    }
    return 0;
}

template<typename T>
inline T Rand_64(T min, T max) {
    std::uniform_int_distribution<T> dis(min, max);
    return dis(engine_64);
}
#endif //DEMO_RAND_HELPER_H
